package com.douqu.game.core.config.goods;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * @author: Gavin.
 * Description:
 * Date: 2017/11/1 0001 下午 6:55
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class AccessoryIntensifyConfig extends GameObject {

    public int unlockLevel;
    public CommonData[] exp;
    public CommonData [] totalExp;
    /**返还的道具，资源，装备*/
    public GoodsData[] restitution;

    public int getTotalExp(int quality){

        for (CommonData commonData :totalExp){
            if(quality == commonData.id)
                return commonData.value;
        }
        return 0;
    }


    @Override
    public boolean check() {
        if(restitution == null)
        {
            LogUtils.error("AccessoryIntensify check restitution is null -> id:" + id + " name:" + name);
            return false;
        }
        return true;
    }


    @Override
    public boolean setVariable(String key, String value) {
        if("exp".equals(key)){
            exp = LoadUtils.loadCommonDataToArray(key, value);
//            return LoadUtils.checkCommonData(exp, this.getClass(), key, DataFactory.ASSET_KEY, id);
            return true;
        }
        else if("totalExp".equals(key)){
            totalExp = LoadUtils.loadCommonDataToArray(key,value);
//            return LoadUtils.checkCommonData(exp, this.getClass(), key, DataFactory.ASSET_KEY, id);
            return true;
        }
        else if("restitution".equals(key))
        {
            restitution = LoadUtils.loadGoodDataToArray(key, value);
            GoodsData[] checkData = new GoodsData[restitution.length];
            for(int i = 0; i < restitution.length; i ++){
                checkData[i] = new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE,
                        restitution[i].id, restitution[i].value);
            }
            return LoadUtils.checkGoods(checkData, this.getClass(), key, id);
        }else{
            return super.setVariable(key, value);
        }
    }

    @Override
    public String toString() {
        return "AccessoryIntensify{" +
                "restitution=" + restitution +
                '}';
    }
}
